﻿using Abp.Application.Services.Dto;
using Abp.Web.Mvc.Authorization;
using Akso.Authorization;
using Akso.ItemDetails;
using Akso.Web.Areas.PSSModule.Models.ItemDetails;
using Akso.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Akso.Web.Areas.PSSModule.Controllers
{
    public class ItemDetailsController : AbpZeroTemplateControllerBase
    {
        // GET: PSSModule/ItemDetails
        private readonly IItemDetailAppService _itemItemDetailsAppService;
        public ItemDetailsController(IItemDetailAppService itemItemDetailsAppService)
        {
            _itemItemDetailsAppService = itemItemDetailsAppService;
        }
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 为新增、编辑数据页面加载数据，弹出修改页面框。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_PSSModule_ItemDetails_Create, AppPermissions.Pages_PSSModule_ItemDetails_Edit)]
        public async Task<PartialViewResult> CreateOrEditModal(Guid? id, Guid itemCategoryId)
        {

            var output = await _itemItemDetailsAppService.GetObjectForEdit(new NullableIdDto<Guid> { Id = id });
            if (itemCategoryId != null)
                output.ItemDetail.ItemCategoryId = itemCategoryId;
            var viewModel = new CreateOrEditItemDetailModalViewModel(output);

            return PartialView("_CreateOrEditModal", viewModel);
        }
    }
}